package com.sina.weibo.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.sina.weibo.LookAroundListActivity;
import com.sina.weibo.RPCHelper;
import com.sina.weibo.RPCHelper.HttpException;
import com.sina.weibo.StaticInfo;
import com.sina.weibo.Utils;
import com.sina.weibo.models.User;
import com.sina.weibo.models.UserRankItem;
import java.io.File;
import java.util.Date;
import java.util.Hashtable;
import java.util.Map;

public class UserRankItemView extends LinearLayout
  implements MainListItemView, View.OnClickListener
{
  private static Map<String, ListView> downloading = new Hashtable();
  private final int ATTEND_ADD = 1;
  private final int ATTEND_CANCEL = 0;
  private Context context;
  private Button mAttendBtn;
  private String mCacheDir;
  private TextView mNickname;
  private TextView mNum;
  private ImageView mPortrait;
  private int mReadMode;
  private UserRankItem mUri;
  private ListView parent;

  public UserRankItemView(Context paramContext, ListView paramListView, UserRankItem paramUserRankItem, boolean paramBoolean1, boolean paramBoolean2, int paramInt)
  {
    super(paramContext);
    this.context = paramContext;
    this.parent = paramListView;
    String str = paramContext.getCacheDir().getAbsolutePath();
    this.mCacheDir = str;
    View localView = ((LayoutInflater)paramContext.getSystemService("layout_inflater")).inflate(2130903052, this);
    TextView localTextView1 = (TextView)findViewById(2131623996);
    this.mNickname = localTextView1;
    TextView localTextView2 = (TextView)findViewById(2131623997);
    this.mNum = localTextView2;
    ImageView localImageView = (ImageView)findViewById(2131623993);
    this.mPortrait = localImageView;
    Button localButton = (Button)findViewById(2131623994);
    this.mAttendBtn = localButton;
    this.mAttendBtn.setOnClickListener(this);
    this.mReadMode = paramInt;
    UserRankItemView localUserRankItemView = this;
    UserRankItem localUserRankItem = paramUserRankItem;
    boolean bool1 = paramBoolean1;
    boolean bool2 = paramBoolean2;
    int i = paramInt;
    localUserRankItemView.update(localUserRankItem, bool1, bool2, 0, i);
  }

  public void onClick(View paramView)
  {
    Button localButton = this.mAttendBtn;
    if (paramView == localButton)
    {
      if (this.mUri.relation != 0)
        break label65;
      LookAroundListActivity.mAttendCount += 1;
      AttendTask localAttendTask1 = new AttendTask(null);
      Integer[] arrayOfInteger1 = new Integer[1];
      Integer localInteger1 = Integer.valueOf(1);
      arrayOfInteger1[0] = localInteger1;
      AsyncTask localAsyncTask1 = localAttendTask1.execute(arrayOfInteger1);
    }
    while (true)
    {
      return;
      label65: LookAroundListActivity.mAttendCount -= 1;
      AttendTask localAttendTask2 = new AttendTask(null);
      Integer[] arrayOfInteger2 = new Integer[1];
      Integer localInteger2 = Integer.valueOf(0);
      arrayOfInteger2[0] = localInteger2;
      AsyncTask localAsyncTask2 = localAttendTask2.execute(arrayOfInteger2);
    }
  }

  public void update(Object paramObject, boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, int paramInt)
  {
    UserRankItem localUserRankItem = (UserRankItem)paramObject;
    this.mUri = localUserRankItem;
    if (this.mUri.relation == 1)
    {
      this.mAttendBtn.setBackgroundResource(2130837512);
      this.mAttendBtn.setText(2131427464);
      if (this.mUri.time != null)
      {
        Context localContext = this.context;
        Date localDate = this.mUri.time;
        String str1 = Utils.formatDate(localContext, localDate);
      }
      TextView localTextView1 = this.mNum;
      String str2 = String.valueOf(this.context.getString(2131427455));
      StringBuilder localStringBuilder1 = new StringBuilder(str2);
      int i = this.mUri.num;
      StringBuilder localStringBuilder2 = localStringBuilder1.append(i);
      String str3 = this.context.getString(2131427458);
      String str4 = str3;
      localTextView1.setText(str4);
      TextView localTextView2 = this.mNickname;
      String str5 = this.mUri.nick;
      localTextView2.setText(str5);
      if (this.mReadMode != 1)
        break label215;
      this.mPortrait.setVisibility(8);
    }
    while (true)
    {
      return;
      this.mAttendBtn.setBackgroundResource(2130837515);
      this.mAttendBtn.setText(2131427709);
      break;
      label215: this.mPortrait.setVisibility(0);
      if (this.mUri.portrait == null)
      {
        ImageView localImageView1 = this.mPortrait;
        Bitmap localBitmap1 = Utils.outputRoundRectBitmap(BitmapFactory.decodeResource(this.context.getResources(), 2130838011));
        localImageView1.setImageBitmap(localBitmap1);
        continue;
      }
      ImageView localImageView2 = this.mPortrait;
      Bitmap localBitmap2 = Utils.outputRoundRectBitmap(BitmapFactory.decodeResource(this.context.getResources(), 2130838011));
      localImageView2.setImageBitmap(localBitmap2);
      Map localMap1 = downloading;
      String str6 = this.mUri.portrait;
      if (localMap1.containsKey(str6))
        continue;
      String str7 = this.mCacheDir;
      String str8 = this.mUri.portrait;
      String str9 = Utils.checkCache(str7, str8);
      if (str9 == null)
      {
        Map localMap2 = downloading;
        String str10 = this.mUri.portrait;
        ListView localListView = this.parent;
        Object localObject = localMap2.put(str10, localListView);
        LoadPortraitTask localLoadPortraitTask = new LoadPortraitTask(null);
        String[] arrayOfString = new String[1];
        String str11 = this.mUri.portrait;
        arrayOfString[0] = str11;
        AsyncTask localAsyncTask = localLoadPortraitTask.execute(arrayOfString);
        continue;
      }
      Bitmap localBitmap3 = BitmapFactory.decodeFile(str9);
      if (localBitmap3 != null)
      {
        ImageView localImageView3 = this.mPortrait;
        Bitmap localBitmap4 = Utils.outputRoundRectBitmap(localBitmap3);
        localImageView3.setImageBitmap(localBitmap4);
        continue;
      }
      boolean bool = new File(str9).delete();
      ImageView localImageView4 = this.mPortrait;
      Bitmap localBitmap5 = Utils.outputRoundRectBitmap(BitmapFactory.decodeResource(this.context.getResources(), 2130838011));
      localImageView4.setImageBitmap(localBitmap5);
    }
  }

  class AttendTask extends AsyncTask<Integer, Void, Boolean>
  {
    private AttendTask()
    {
    }

    protected Boolean doInBackground(Integer[] paramArrayOfInteger)
    {
      int i = paramArrayOfInteger[0].intValue();
      int j = 0;
      switch (i)
      {
      default:
      case 1:
      case 0:
      }
      while (true)
      {
        return Boolean.valueOf(j);
        try
        {
          RPCHelper localRPCHelper1 = RPCHelper.getInstance(UserRankItemView.this.getContext());
          User localUser1 = StaticInfo.mUser;
          String str1 = UserRankItemView.this.mUri.uid;
          boolean bool1 = localRPCHelper1.addComment(localUser1, str1);
          int k = 1;
          continue;
          RPCHelper localRPCHelper2 = RPCHelper.getInstance(UserRankItemView.this.getContext());
          User localUser2 = StaticInfo.mUser;
          String str2 = UserRankItemView.this.mUri.uid;
          boolean bool2 = localRPCHelper2.cancelComment(localUser2, str2);
          boolean bool3 = bool2;
          k = 1;
        }
        catch (RPCHelper.HttpException localHttpException)
        {
        }
      }
    }

    protected void onPostExecute(Boolean paramBoolean)
    {
      UserRankItem localUserRankItem;
      if (paramBoolean.booleanValue())
      {
        if (UserRankItemView.this.mUri.relation != 0)
          break label75;
        UserRankItemView.this.mAttendBtn.setBackgroundResource(2130837512);
        UserRankItemView.this.mAttendBtn.setText(2131427464);
        localUserRankItem = UserRankItemView.this.mUri;
        if (UserRankItemView.this.mUri.relation - 1 != 0)
          break label102;
      }
      label75: label102: for (int i = 0; ; i = 1)
      {
        localUserRankItem.relation = i;
        return;
        UserRankItemView.this.mAttendBtn.setBackgroundResource(2130837515);
        UserRankItemView.this.mAttendBtn.setText(2131427709);
        break;
      }
    }
  }

  class LoadPortraitTask extends AsyncTask<String, Void, String[]>
  {
    private LoadPortraitTask()
    {
    }

    protected String[] doInBackground(String[] paramArrayOfString)
    {
      String[] arrayOfString = new String[2];
      String str1 = paramArrayOfString[0];
      int i = 0;
      try
      {
        RPCHelper localRPCHelper = RPCHelper.getInstance(UserRankItemView.this.getContext());
        String str2 = UserRankItemView.this.context.getCacheDir().getAbsolutePath();
        String str3 = localRPCHelper.getPicture(str1, str2);
        File localFile = new File(str3);
        if (localFile.exists())
        {
          String str4 = localFile.toString();
          localObject = str4;
        }
        arrayOfString[0] = str1;
        arrayOfString[1] = localObject;
        return arrayOfString;
      }
      catch (Exception localException)
      {
        while (true)
          Object localObject = null;
      }
    }

    protected void onPostExecute(String[] paramArrayOfString)
    {
      String str1 = paramArrayOfString[0];
      String str2 = paramArrayOfString[1];
      ListView localListView;
      Bitmap localBitmap1;
      int k;
      if (str2 != null)
      {
        localListView = (ListView)UserRankItemView.downloading.get(str1);
        localBitmap1 = BitmapFactory.decodeFile(str2);
        int i = localListView.getFirstVisiblePosition();
        int j = localListView.getChildCount();
        k = 0;
        if (k >= j)
          Object localObject = UserRankItemView.downloading.remove(str1);
      }
      else
      {
        return;
      }
      if (!(localListView.getChildAt(k) instanceof UserFansItemView));
      while (true)
      {
        k += 1;
        break;
        UserRankItemView localUserRankItemView = (UserRankItemView)localListView.getChildAt(k);
        if (!localUserRankItemView.mUri.portrait.equals(str1))
          continue;
        if (localBitmap1 != null)
        {
          if (localBitmap1.isRecycled())
            localBitmap1 = BitmapFactory.decodeFile(str2);
          ImageView localImageView1 = localUserRankItemView.mPortrait;
          Bitmap localBitmap2 = Utils.outputRoundRectBitmap(localBitmap1);
          localImageView1.setImageBitmap(localBitmap2);
          continue;
        }
        ImageView localImageView2 = UserRankItemView.this.mPortrait;
        Bitmap localBitmap3 = Utils.outputRoundRectBitmap(BitmapFactory.decodeResource(UserRankItemView.this.context.getResources(), 2130838011));
        localImageView2.setImageBitmap(localBitmap3);
      }
    }

    protected void onPreExecute()
    {
    }

    protected void onProgressUpdate(Void[] paramArrayOfVoid)
    {
    }
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     com.sina.weibo.view.UserRankItemView
 * JD-Core Version:    0.6.0
 */